/**
 * create by young (young2f@outlook.com) on 2020/9/16
 */


'use strict';
import React from 'react';
import {Form, Timeline} from 'antd';

import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';

import ViewTitle from "../../../components/ViewTitle";

moment.locale('zh-cn');

@Form.create()
@connect(({user, global, sales}) => ({...user, ...sales, ...global}))
export default class ModalSalesOrderHistroy extends FormBase {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
    const {code, dispatch} = this.props;
    dispatch && dispatch({
      type: 'sales/history',
      payload: {code},
    });

  }

  cols = [
    {
      title: '操作时间', key: 'createdTs', dataIndex: 'createdTs', render: value => {
        return <div>{moment(value).format('YYYY-MM-DD HH:mm:ss')}</div>
      }
    },
    {title: '操作者', key: 'createUsername', dataIndex: 'createUsername'},
    {title: '操作事项', key: 'name', dataIndex: 'name'},

  ]

  getTimeLineItem() {
    const { orderHistory,} = this.props;
    const temp = [];
    _.map(orderHistory, item => {
      const {createdTs, name, createUsername} = item;
      temp.push(
        <Timeline.Item>{`操作时间：${moment(createdTs).format('YYYY-MM-DD HH:mm:ss')}，操作者：${createUsername}，操作内容：${name}`}</Timeline.Item>
      )
    })
    return temp;
  }

  render() {
    const {style, orderHistory,} = this.props;
    console.log('orderHistory', orderHistory)
    return (
      <div style={{...style}}>
        <ViewTitle
          title={'订单历程'}
          level={1}
        ></ViewTitle>
        <Timeline>
          {this.getTimeLineItem()}
        </Timeline>
      </div>

    );
  }
}

